//
//  ViewController.m
//  NSObjectMethod
//
//  Created by lzy on 17/1/19.
//  Copyright © 2017年 NumberFive. All rights reserved.
//

#import "ViewController.h"
#import <objc/runtime.h>
#import <objc/objc.h>
#import <objc/message.h>


void dynamicMethodIMP(id self, SEL _cmd) {
    NSLog(@" >> dynamicMethodIMP");
}



@interface XXXDuck : UIButton

- (void)button:(NSString *)x y:(int)y;

@end

@implementation XXXDuck

- (void)dealloc {

}

@end

@interface ViewController ()

- (void)add;
- (NSArray *)fun1:(NSString *)str;

+ (void)testClassMethod;

@property (nonatomic, class, assign) NSUInteger count;

@end

static NSUInteger _count;
@implementation ViewController
{
    XXXDuck *_duckButton;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    ViewController.count = 1;
    NSUInteger count = ViewController.count;
    XXXDuck *button = [[XXXDuck alloc] initWithFrame:CGRectMake(30, 60, 100, 30)];
    [self.view addSubview:button];
    [button setBackgroundColor:[UIColor redColor]];
    [button addTarget:self
               action:@selector(action)
     forControlEvents:UIControlEventTouchUpInside];
    _duckButton = button;
    
    [self add];
    
    XXXDuck *dd = [XXXDuck new];
    [dd button:@"111" y:345];
}
- (void)action {
    ///< 发送一个不存在的方法
    ((void (*)(id, SEL, NSUInteger,BOOL))(void *) objc_msgSend)((id)_duckButton, NSSelectorFromString(@"_inexistenceMethod:c:"), 200,YES);
}

+ (void)setCount:(NSUInteger)count {
    _count = count;
}

+ (NSUInteger)count {
    return _count;
}

@end



